﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace BlockeyEssentials.Geometry
{
    public class Circle
    {
        public Circle(Vector2 oPosition, float oRadius)
        {
            Position = oPosition;
            Radius = oRadius;
        }

        #region Methods

        public static bool Collision(Circle a, Circle b)
        {
            float oMaxDistance
                = a.Radius + b.Radius;

            float oDistance
                = Vector2.Distance(a.Position, b.Position);

            if (oDistance <= oMaxDistance)
                return true;

            return false;
        }

        public void DrawDebug(Color oColor)
        {
            float oLayerOrder = 1.0f;
            Draw(All.SpriteBatch_Debug, oColor, All.Texture_Circle, oLayerOrder);
        }

        public void Draw(SpriteBatch oSB, Color oColor, Texture2D oTexture, float oLayerOrder)
        {
            Vector2 oTextureBounds
                = new Vector2(oTexture.Width, oTexture.Height);

            Vector2 oOrigin = oTextureBounds / 2;
            Vector2 oScale = new Vector2(2 * Radius / oTextureBounds.X, 2 * Radius / oTextureBounds.Y);

            oSB.Draw(oTexture, Position, null, oColor,
                0.0f, oOrigin, oScale, SpriteEffects.None, oLayerOrder);
        }

        #endregion

        #region Properties

        /// <summary>
        /// Returns the Diameter
        /// </summary>
        public float Diameter
        {
            get { return Radius * 2; }
        }

        /// <summary>
        /// Returns the Radius
        /// </summary>
        public float Radius
        {
            get { return _Radius; }
            set
            {
                if (value > 0 && value < 10000)
                    _Radius = value;
            }
        }

        /// <summary>
        /// Returns the Position
        /// </summary>
        public Vector2 Position
        {
            get { return _Position; }
            set { _Position = value; }
        }

        #endregion

        private Vector2 _Position;
        private float   _Radius;

    }
}
